package com.dai.helloc

import android.app.Service
import android.content.Intent
import android.os.Handler
import android.os.IBinder
import android.os.Process
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.File
import kotlin.concurrent.thread
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

class EntryService : Service() {

    companion object{
        init {
            System.loadLibrary("native-lib")
        }
    }

    override fun onCreate() {
        super.onCreate()
        MyLog.info("EntryService::onCreate called!")
        MyLog.info("EntryService 进程为:${android.os.Process.myPid()}")
        startEventLoop()

//        val file1 = File(filesDir.absolutePath + "/p1.txt")
//        MyLog.info("file1 full path:${file1.absolutePath}")
//        if (!file1.exists()){
//            val ret = file1.createNewFile()
//            MyLog.info("创建文件结果为:${ret}")
//        }else{
//            MyLog.info("file1已存在!")
//        }
//        thread {
//            startOrphanProcess(file1.absolutePath)
//        }

        startXX()
    }

    external fun startXX():Unit

    external fun startOrphanProcess(filePath1:String):Unit

//    external fun xxoo():Unit

    override fun onBind(intent: Intent?): IBinder? {
        return null
    }

    var counter = 0
    private fun startEventLoop(){
//        CoroutineScope(Dispatchers.Default).launch {
//            while (true){
//                delay(2000)
//                counter++
//                MyLog.info("counter:$counter")
//            }
//        }
    }
}